package com.auction.mapper;

import com.auction.dto.UserPageQueryDTO;
import com.auction.pojo.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 插入用户
     *
     * @param user 用户对象
     */
    @Insert("INSERT INTO user (name, username, password, phone, sex, id_number, status, create_time, update_time) " +
            "VALUES (#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(User user);

    /**
     * 分页查询用户列表
     * @param userPageQueryDTO
     * @return
     */
    Page<User> pageQueryUser(UserPageQueryDTO userPageQueryDTO);

    /**
     * 更新用户信息
     *
     * @param user 用户对象
     */
    void update(User user);

    /**
     * 根据ID查询用户
     *
     * @param id 用户ID
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectById(Long id);

    /**
     * 根据用户名查询用户
     * 
     * @param username 用户名
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE username = #{username}")
    User selectByUsername(String username);

    /**
     * 根据身份证号查询用户
     * 
     * @param idNumber 身份证号
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE id_number = #{idNumber}")
    User selectByIdNumber(String idNumber);


    /**
     * 根据姓名模糊查询用户列表
     * 
     * @param name 用户名
     * @return 用户列表
     */
    @Select("SELECT * FROM user WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<User> selectByName(@Param("name") String name);

}